<template>
  <div class="client-container">
    <!-- 顶部导航栏 -->
    <div class="top-nav-bar">
      <div class="title">
        <img src="@/assets/images/logo2.svg" alt="logo">
        熊猫小工具
      </div>
      <el-menu
          :default-active="activeModule"
          mode="horizontal"
          background-color="#ffffff"
          text-color="#333333"
          active-text-color="#409EFF"
          :router="true"
      >
        <el-menu-item index="/paper">论文降重</el-menu-item>
        <el-menu-item index="/module2">模块2沙发发</el-menu-item>
        <el-menu-item index="/module3">模块3</el-menu-item>
      </el-menu>
    </div>

    <!-- 用户头像 -->
    <el-dropdown class="user-avatar" @command="handleUserCommand">
      <el-avatar icon="el-icon-user-solid"></el-avatar>
      <el-dropdown-menu slot="dropdown">
        <el-dropdown-item command="profile">个人资料</el-dropdown-item>
        <el-dropdown-item command="logout">退出登录</el-dropdown-item>
      </el-dropdown-menu>
    </el-dropdown>

    <!-- 客服服务 -->
    <div class="service">
      <el-popover placement="left" trigger="hover">
        <div slot="default" class="service-hover-content">
          <img src="@/assets/images/weixin.png" alt="客服">
          <div>扫描二维码，</div>
          <div>联系售前/售后客服</div>
        </div>
        <div slot="reference" class="service-item">
          <img src="@/assets/images/kefu.png" alt="客服"/>
          <span>人工客服</span>
        </div>
      </el-popover>

    </div>

    <!-- 模块内容区域 -->
    <div class="content-area">
      <Transition name="slide-fade" mode="out-in" :duration="{ enter: 500, leave: 200 }">
        <router-view></router-view>
      </Transition>
    </div>

    <!-- 弹出登录框 -->
    <el-dialog
        :visible.sync="loginDialogVisible"
        width="35%"
        :show-close="false"
        :before-close="loginDialogHandleClose"
    >
      <Login></Login>
    </el-dialog>

  </div>
</template>

<script>
import LoginUser from "@/components/loginUser.vue";
import {autoBindEvents, emitEvent} from "@/js/EventBus.js";

export default {
  name: 'index',
  components: {Login: LoginUser},
  data() {
    return {
      // 当前激活的模块
      activeModule: 'module1',
      // 待转化的内容
      inputValue: '',
      loginDialogVisible: false
    }
  },
  created() {
    autoBindEvents(this, {
      showLogin: this.showLogin,
      closeLogin: this.closeLogin,
    });
  },
  methods: {
    // 处理用户命令
    handleUserCommand(command) {
      if (command === 'logout') {
        // 可以在这里添加退出登录的具体逻辑
        let token = this.$storage.get("token");
        if (!token) {
          return
        }
        let JWTObj = this.$kunUtil.parseJwt(token);
        this.$api.user.logout(JWTObj.userinfo.userId).then(() => {
          this.$message({message: '已退出登录', type: 'success'});
          this.$storage.remove("token");
        }).catch(err => {
          this.$message({message: '登出失败', type: 'error'});
        })

      } else if (command === 'profile') {
        // 可以在这里添加查看个人资料的具体逻辑
        if (this.$kunUtil.judgeUserType() === this.$sys.userType.USER) {
          this.$router.push('/user/userProfile');
        } else {
          emitEvent('showLogin', {from: "个人中心"})
          this.$message.error('请先登录!')
        }
      }
    },

    loginDialogHandleClose() {
      this.loginDialogVisible = false
    },
    showLogin(payload) {
      console.log('showLogin', payload)
      this.loginDialogVisible = true
    },
    closeLogin(payload) {
      console.log('closeLogin', payload)
      this.loginDialogVisible = false
    },

  }
}
</script>

<style lang="less" scoped>
.client-container {
  position: relative;
  min-height: 100vh;

  .top-nav-bar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 1000;
    border-bottom: 1px solid #ebeef5;
    display: flex;
    align-items: center;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    backdrop-filter: blur(10px);
    background-color: rgba(255, 255, 255, 0.8);

    .title {
      font-size: 30px;
      font-weight: bold;
      margin-left: 20px;
      margin-right: 100px;
      display: flex;
      align-items: center;
      font-family: "jiangxi2";

      &:hover{
        cursor: pointer;
      }
      img {
        width: 30px;
        height: 30px;
        margin-right: 10px;
      }
    }

    // 修改 el-menu-item 的样式
    .el-menu-item {
      font-size: 18px;
      margin: 0 15px;
      transition: all 0s ease; // 快速解决闪烁问题

      &:hover {
        background-color: transparent !important;
        color: #409EFF !important;
      }

      &.is-active {
        border-bottom: none !important; // 强制移除下划线
        font-weight: bold;
        color: #409EFF;
      }
    }

  }

  .user-avatar {
    position: fixed;
    top: 10px;
    right: 20px;
    z-index: 1001;
  }

  .service {
    position: fixed;
    right: 20px;
    bottom: 200px;
    width: 50px;


    .service-item {
      img {
        width: 30px;
        height: 30px;
      }

      margin-top: 10px;
      padding: 5px;
      background-color: #ffffff;
      border-radius: 5px;
      cursor: pointer;
      display: flex;
      justify-content: center;
      align-items: center;
      flex-wrap: wrap;

      span {
        text-align: center;
      }
    }


  }

  .content-area {
    max-width: 80vw;
    min-height: calc(100vh - 80px);
    padding: 80px 10vw 0;
    background-image: radial-gradient(#ddebfe, #f2f2fe 100%)
  }
}

.service-hover-content {
  img {
    width: 130px;
    height: 130px
  }

  color: #495057;
  text-align: center
}

/* 过渡动画 */
.slide-fade-enter-active,
.slide-fade-leave-active {
  transition: opacity 0.4s ease-in-out,
  transform 0.5s cubic-bezier(0.25, 0.8, 0.5, 1);
}

.slide-fade-enter-from {
  opacity: 0;
  transform: translateX(-30px);
}

.slide-fade-leave-to {
  opacity: 0;
  transform: translateX(30px);
}


:deep(.el-dialog .el-dialog__header) {
  padding: 0;
}

:deep(.el-dialog .el-dialog__body) {
  padding: 0;
}
</style>
